<template>
  <hm-layout :customStyle="{ 'background': '#f7f7fa' }">
    <view class="mall-wrap">
      <view class="mall-goods-list">
        <view v-for="goods in goodsList" :key="goods._id" class="goods-card" @click="goDetail(goods._id)">
          <view class="goods-img">
            <view class="goods-img_left">
              <el-image class="img" :src="goods.rendering_url[0]"></el-image>
            </view>
            <view class="goods-img_right">
              <el-image class="img ss-m-b-10" :src="goods.rendering_url[1]"></el-image>
              <el-image class="img" :src="goods.rendering_url[2]"></el-image>
            </view>
          </view>
          <view class="goods-name-wrap">
            <view class="goods-name ss-line-1">{{ goods.goods_name }}</view>
            <view class="sur-name-num">{{ goods.surname_nums}}张</view>
          </view>
          <view class="tags-list">
            <view class="tag-item" v-if="goods.is_original">原创</view>
            <view class="tag-item" v-if="goods.contain_keyword">含关键词</view>
            <view class="tag-item" v-if="goods.contain_underlay">含底图</view>
          </view>
          <view class="goods-buy">
            <view class="goods-price">￥<text class="price">{{ goods.diplayPrice }}</text></view>
            <view class="buy-btn ui-BG-Main-Gradient">购买</view>
          </view>
        </view>
      </view>
    </view>
  </hm-layout>
</template>

<script setup>
  import { ref, onMounted } from 'vue'
  let goodsList = ref([])
  let pageIndex = ref(1)
  let pageSize = ref(20)
	var vk = uni.vk;
  
  const goDetail = (_id) => {
    vk.navigateTo(`/pages/goods-detail/goods-detail?_id=${_id}`);
  }
  
  let fetchGoodsList = () => {
    vk.callFunction({
    	url: 'client/goods/pub/getList',
    	title: '努力加载中...',
    	data: {
    		pageIndex: pageIndex.value,
    		pageSize: pageSize.value
    	},
    	success(data) {
    		const { rows = [] } = data;
    		goodsList.value = goodsList.value.concat(rows);
    	},
    	fail(error) {
    		vk.toast('查询失败,请稍后再试!');
    	},
    });
  }
  
  onMounted(() => {
    fetchGoodsList()
  })
</script>
<style lang="scss" scoped>
.mall-wrap {
  width: 1310px;
  margin: auto;
  padding: 30px;
  
  .mall-goods-list {
    display: flex;
    flex-wrap: wrap;
    .goods-card {
      width: 250px;
      box-sizing: border-box;
      background-color: #fff;
      color: #000;
      padding: 10px 10px 20px;
      border-radius: 5px;
      margin-right: 15px;
      cursor: pointer;
      margin-bottom: 15px;
      transition: all 0.3s;
      
      
      &:hover {
        box-shadow: 0 4px 8px 0 rgba(0,0,0,.1);
        position: relative;
        transform: translateY(-2px);
      }
      
      &:nth-child(5n) {
        margin-right: 0;
      }
      
      .goods-img {
        display: flex;
        .goods-img_left {
          .img {
            width: 150px;
            height: 150px;
          }
        }
        .goods-img_right {
          display: flex;
          flex-direction: column;
          margin-left: 10px;
          .img {
            width: 70px;
            height: 70px;
          }
        }
      }
      .goods-name-wrap {
        margin-top: 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #333;
        font-size: 16px;
        font-weight: 500;
        
        .goods-name {
          width: 180px;
        }
      }
      
      .tags-list {
        display: flex;
        margin-top: 8px;
        height: 20px;
        .tag-item {
          margin-right: 6px;
          padding: 2px 4px;
          color: #ff5000;
          font-size: 10px;
          vertical-align: top;
          border: 1px solid #ff5000;
        }
      }
      .goods-buy {
        margin-top: 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        
        .goods-price {
          color: var(--ui-BG-Main);
          .price {
            font-weight: bold;
            font-size: 24px;
          }
        }
        .buy-btn {
          width: 80px;
          text-align: center;
          height: 28px;
          line-height: 28px;
          border-radius: 15px;
          font-size: 14px;
        }
      }
    }
  }
}
</style>